package com.adinnet.api.information.controller;


import com.adinnet.api.information.model.Information;
import com.adinnet.api.information.service.InformationService;
import com.adinnet.core.JsonResult;
import com.adinnet.core.PageParam;
import com.adinnet.core.PageResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 资讯管理 前端控制器
 * </p>
 *
 * @author chenjia
 * @since 2020-12-03
 */
@RestController
@RequestMapping("api/information")
public class InformationController {

    @Autowired
    private InformationService informationService;

    /**
     * 查询资讯列表
     * @return
     */
    @GetMapping("list")
    public PageResp list(@RequestParam(value = "page") Long page,@RequestParam(value = "limit") Long limit) {
        try {
            if(page==null){
                return new PageResp("page不能为空");
            }
            if(limit==null){
                return new PageResp("limit不能为空");
            }
            PageParam pageParam = new PageParam();
            pageParam.setPage(page);
            pageParam.setLimit(limit);
            return informationService.queryList(pageParam);
        }catch (Exception e){
            return new PageResp("查询失败");
        }
    }

    /**
     * 查询资讯详情
     * @return
     */
    @GetMapping("details")
    public JsonResult details(@RequestParam(value = "infoId") Integer infoId) {
        try {
            Information information = informationService.getById(infoId);
            return JsonResult.ok().put("data",information);
        }catch (Exception e){
            return JsonResult.error("操作失败");
        }
    }

}
